package controllers;

import play.mvc.Before;
import util.Util;
import models.*;

public class Security extends Secure.Security {

	static boolean authentify(String uname, String upass) {
		System.out.println("dasfasd");
//		Manager manager = Manager.find("from Manager where mannum = ? and manpass = ?", uname,Util.md5(upass)).first();
		return !session.contains("username");
//		return manager != null;
    }
    
    static boolean check(String profile) {	
    	System.out.println(profile+"++++++++++++++++++++++++++++++++++++++++++++");
		String username = session.get("username");
		String aid = session.get("aid");
//		if (session.contains("username")) {
//			return true;
//		}
		Manager manager = Manager.findById(Long.parseLong(aid));
		if(manager == null){
			return false;
		}
		if(manager != null){
			Permis permis = Permis.find("from Permis where percode = ?", profile).first();
			if(permis != null){
				PermisAmong perma = PermisAmong.find("from PermisAmong where mgid = ? and perid = ?",manager.id, permis.id).first();
				if(perma != null){
					System.out.println("yes----------------------------------------------------");
					return true ;					
				}
			}
			return false;
		}
		System.out.println("no+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        return false;
    }
    
    
}
